#pragma once
#include "Protocol.hpp"

class Calculator
{
public:
    Calculator() {}
    ~Calculator() {}
    Response Excute(const Request &req)
    {
        Response res;
        switch (req.Oper())
        {
        case '+':
            res.SetResult(req.X() + req.Y());
            res.SetCode(0);
            break;
        case '-':
            res.SetResult(req.X() - req.Y());
            res.SetCode(0);
            break;
        case '*':
            res.SetResult(req.X() * req.Y());
            res.SetCode(0);
            break;
        case '/':
            if (req.Y() == 0)
            {
                res.SetCode(1);
            }
            else
            {
                res.SetResult(req.X() / req.Y());
                res.SetCode(0);
            }

            break;
        case '%':
            if (req.Y() == 0)
            {
                res.SetCode(2);
            }
            else
            {
                res.SetResult(req.X() / req.Y());
                res.SetCode(0);
            }
            break;
        default:
            res.SetCode(3);
            break;
        }
        return res;
    }
};